<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/2/7
 * Time: 17:09
 */
declare(strict_types=1);

namespace App\Process;
// use App\Task\MchAccountAccessTask;
use App\Utils\CustomUtils;
use App\Utils\RedisUtils;
use Hyperf\Process\AbstractProcess;
use Hyperf\Utils\ApplicationContext;
use Hyperf\Di\Annotation\Inject;
use App\Service\EmailService;
use App\Constants\XZXResponseCode;

/**
 * Class EmailProcess
 * @package App\Process
 */
class EmailProcess extends AbstractProcess
{

    public $name = 'email-sender';

    /**
     * @Inject()
     * @var EmailService
     */
    private $EmailService;

    public function handle(): void
    {
        while(true){
            // 读取Redis，出栈一条数据，进行处理
            $cache = RedisUtils::redisResource()->lPop("EmailList");
            if(!$cache)
            {

                sleep(1);
            }
            else
            {
                CustomUtils::xzxDebug($cache);
                $result = $this->EmailService->send(unserialize($cache));
                if (!$result) {
                    CustomUtils::xzxDebug('处理Email失败：data:' . $cache);
                }
                sleep(60);
                // CustomUtils::xzxDebug(SUCCESS_CODE);
                // try {
                //     $container = ApplicationContext::getContainer();
                //     $task = $container->get(MchAccountAccessTask::class);
                //     $task->handle($cache);
                // } catch (\Throwable $th) {
                //     CustomUtils::xzxDebug($th->getMessage());
                // }
            }
        }


    }

}
